/*
 *Coprright (c) feng mang studio. all rights reserved.
 *
 *build time: 2014/6/26/10:34
 *
 *file name:food.cpp
 *
 *Edition:1.0
 *
 *founder:bluekey
 *
 *description:The design of the food.
 */

#include"head/food.h"
#include<curses.h>
#include<vector>
#include<unisted.h>
#include"head/snake.h"
using namespace std;

bool food::new_food(vector<body> &Snake)
{
	int a,b;
	int sum = 0;
	bool flag=true;
	while (true)
	{
		flag = true;
		srand(time(NULL));
		a = rand()%(COLS-1);
		srand(time(NULL));
		b = rand()%(LINES-1);
		for (vector<body>::size_type i = 0; i < Snake.size(); i++)
		{
			if(Snake[i].get_x() == b && Snake[i].get_y() == a)
			{
				flag = false;
			}
		}
		sum++;
		if (flag)
		{
			set_x() = b;
			set_y() = a;
			break;
		}
		if(sum > 1000)
		{
			return false;
		}
	}
	return true;
}

bool food::eat_food(vector<body> &Snake)
{
	if ((Snake[0].get_x() == get_x())  &&  (Snake[0].get_x() == get_x()))
	{
		return true;
	}
	else
	{
		return false;
	}
}
